package com.wamke.controller;

import com.wamke.pojo.Emplyoee;
import com.wamke.pojo.EmplyoeeDTO;
import com.wamke.pojo.PageBean;
import com.wamke.pojo.Result;
import com.wamke.service.EmplyoeeService;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: wanke
 * @ClassName EmplyoeeController
 * @author: WXK
 * @create: 2023-10-20 16:05
 **/
@RestController
@RequestMapping("/emp")
@Slf4j
public class EmplyoeeController {

    @Autowired
    private EmplyoeeService emplyoeeService;


    @GetMapping("/page") //查询所有数据
    public Result<List<Emplyoee>> page(){
        List<Emplyoee> list =  emplyoeeService.select();
        return Result.success(list);
    }


    @GetMapping("/condition") //条件查询
    public Result<PageBean> condition( EmplyoeeDTO emplyoeeDTO){
       PageBean pageBean = emplyoeeService.selectByCondition(emplyoeeDTO);
        return Result.success(pageBean);
    }
    //修改回显
    @GetMapping("/{id}")
    public Result<Emplyoee> getById(@PathVariable Long id ){
            Emplyoee emplyoee = emplyoeeService.selectById(id);
        return Result.success(emplyoee);
    }
    //修改
    @PutMapping
    public Result update(@RequestBody Emplyoee emplyoee){
        emplyoeeService.update(emplyoee);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable String id ){
        emplyoeeService.delete(id);
        return Result.success();
    }

}
